package com.bcdat.sso_user_management.service.Impl;

import com.bcdat.sso_user_management.service.SimpleHashService;
import org.apache.shiro.crypto.hash.DefaultHashService;
import org.apache.shiro.crypto.hash.HashRequest;
import org.apache.shiro.util.SimpleByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zhaolele
 * @date 2019-09-25 16:06
 */
@Component
public class SimpleHashServiceImpl implements SimpleHashService {
    @Autowired
    DefaultHashService hashService;

    @Override
    public String simpleHash(String salt, String source) {

        HashRequest request = new HashRequest.Builder().setSalt(new SimpleByteSource(salt))
                .setSource(source).build();
        return hashService.computeHash(request).toHex();
    }
}
